/*
 * Created by JFormDesigner on Sun Jun 26 02:17:25 CST 2022
 */

package com.keshe.jsp;

import com.keshe.service.UserContorller;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.*;
import javax.swing.*;
import javax.swing.GroupLayout;

/**
 * @author 1
 */
public class Login extends JFrame {

    public Login() {
        initComponents();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");
        panel1 = new JPanel();
        label1 = new JLabel();
        label2 = new JLabel();
        textField1 = new JTextField();
        label3 = new JLabel();
        button1 = new JButton();
        button2 = new JButton();
        passwordField1 = new JPasswordField();
        action1 = new ZC();
        action2 = new DL();

        //======== this ========
        //setTitle("\u767b\u5f55");
        setTitle("登录");
        setResizable(false);
        setIconImage(new ImageIcon(getClass().getResource("/images/\u9152\u5e97 (1).png")).getImage());
        //setIconImage(new ImageIcon(getClass().getResource("")).getImage());

        Container contentPane = getContentPane();

        //======== panel1 ========
        {

            //---- label1 ----
            label1.setText(bundle.getString("label1.text_9"));
            label1.setIcon(new ImageIcon(getClass().getResource("/images/\u7528\u6237\u540d.png")));

            //---- label2 ----
            label2.setText(bundle.getString("label2.text_5"));
            label2.setIcon(new ImageIcon(getClass().getResource("/images/\u5bc6\u7801.png")));

            //---- label3 ----
            label3.setText(bundle.getString("label3.text_3"));
            label3.setHorizontalAlignment(SwingConstants.CENTER);
            label3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
            label3.setIcon(new ImageIcon(getClass().getResource("/images/\u9152\u5e97 (1).png")));

            //---- button1 ----
            button1.setAction(action1);
            button1.setText(bundle.getString("button1.text_2"));

            //---- button2 ----
            button2.setAction(action2);
            button2.setText(bundle.getString("button2.text_2"));

            GroupLayout panel1Layout = new GroupLayout(panel1);
            panel1.setLayout(panel1Layout);
            panel1Layout.setHorizontalGroup(
                panel1Layout.createParallelGroup()
                    .addComponent(label3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
                            .addGroup(panel1Layout.createSequentialGroup()
                                .addGap(68, 68, 68)
                                .addGroup(panel1Layout.createParallelGroup()
                                    .addComponent(label2)
                                    .addComponent(label1))
                                .addGap(23, 23, 23)
                                .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                                    .addComponent(passwordField1, GroupLayout.PREFERRED_SIZE, 211, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(textField1, GroupLayout.PREFERRED_SIZE, 211, GroupLayout.PREFERRED_SIZE)))
                            .addGroup(panel1Layout.createSequentialGroup()
                                .addGap(85, 85, 85)
                                .addComponent(button1, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(button2, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(73, Short.MAX_VALUE))
            );
            panel1Layout.setVerticalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(label3, GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(textField1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(label1))
                        .addGap(20, 20, 20)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(passwordField1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(label2))
                        .addGap(26, 26, 26)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(button2)
                            .addComponent(button1))
                        .addGap(40, 40, 40))
            );
        }

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(panel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap())
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(panel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap())
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel panel1;
    private JLabel label1;
    private JLabel label2;
    private JTextField textField1;
    private JLabel label3;
    private JButton button1;
    private JButton button2;
    private JPasswordField passwordField1;
    private ZC action1;
    private DL action2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables


    private class ZC extends AbstractAction {
        private ZC() {
            // JFormDesigner - Action initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
            ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");

            putValue(NAME, bundle.getString("action1.Name_8"));
            // JFormDesigner - End of action initialization  //GEN-END:initComponents
        }

        public void actionPerformed(ActionEvent e) {
            // TODO add your code here
            dispose();

            new Register().setVisible(true);
        }
    }

    private class DL extends AbstractAction {
        private DL() {
            // JFormDesigner - Action initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
            ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");

            putValue(NAME, bundle.getString("action2.Name_3"));
            // JFormDesigner - End of action initialization  //GEN-END:initComponents
        }

        public void actionPerformed(ActionEvent e) {
            // TODO add your code here
            UserContorller uc = new UserContorller();
            int flag = uc.login_in(textField1.getText(), String.valueOf(passwordField1.getPassword()));
            if (flag == 1) {
                dispose();//关闭页面
                new Index().setVisible(true);
            }
            if (flag == 0) {
                JOptionPane.showMessageDialog(null,"请输入账号和密码");
            }
            if (flag == -1) {
                JOptionPane.showMessageDialog(null,"密码错误，请重新输入！");
            }
        }
    }
}
